const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        phone:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getUserInfo();
    },
    getUserInfo() {
        let that = this;
        wx.request({
            url: app.globalData.baseUrl + '/sys/getUserInfo',
            method: "GET",
            header: {
                "token": wx.getStorageSync('token')
            },
            success: function (res) {
                if (res.data.code === 200) {
                    that.setData({
                        phone: res.data.result.phone
                    })
                }
            }
        })
    },
    phoneInput(e){
        this.setData({
            phone: e.detail
        })
    },
    save(){
        wx.request({
            url: app.globalData.baseUrl + '/sys/editUserInfo',
            method: "POST",
            data: {
                phone: this.data.phone
            },
            header: {
                "Content-Type": "application/json;charset=utf-8",
                "token": wx.getStorageSync('token')
            },
            success: function (res) {
                if(res.data.code === 200){
                    wx.showToast({
                        title: res.data.msg,
                        icon: 'none',
                        duration: 2000
                    });
                }
                //返回上一级关闭当前页面
                wx.navigateBack({
                    delta: 1
                })
            }
        })
    }


})
